home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / printf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-05  |  2.4 KB  |  120 lines

  1. /* @(#)printf.c    1.11 98/09/05 Copyright 1985 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1985 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <stdio.h>
  23. #include <vadefs.h>
  24. #include <standard.h>
  25.  
  26. #define BFSIZ    256
  27.  
  28. typedef struct {
  29.     short    cnt;
  30.     char    *ptr;
  31.     char    buf[BFSIZ];
  32.     int    count;
  33.     FILE    *f;
  34. } *BUF, _BUF;
  35.  
  36. LOCAL void _bflush    __PR((BUF));
  37. LOCAL void _bput    __PR((char, long));
  38.  
  39. LOCAL void _bflush (bp)
  40.     register BUF    bp;
  41. {
  42.     bp->count += bp->ptr - bp->buf;
  43.     if (filewrite (bp->f, bp->buf, bp->ptr - bp->buf) < 0)
  44.         bp->count = EOF;
  45.     bp->ptr = bp->buf;
  46.     bp->cnt = BFSIZ;
  47. }
  48.  
  49. #ifdef    PROTOTYPES
  50. LOCAL void _bput (char c, long l)
  51. #else
  52. LOCAL void _bput (c, l)
  53.         char    c;
  54.         long    l;
  55. #endif
  56.     register BUF    bp = (BUF)l;
  57.  
  58.     *bp->ptr++ = c;
  59.     if (--bp->cnt <= 0)
  60.         _bflush (bp);
  61. }
  62.  
  63. /* VARARGS2 */
  64. #ifdef    PROTOTYPES
  65. EXPORT int printf(const char *form, ...)
  66. #else
  67. EXPORT int printf(form, va_alist)
  68.     char    *form;
  69.     va_dcl
  70. #endif
  71. {
  72.     va_list    args;
  73.     _BUF    bb;
  74.  
  75.     bb.ptr = bb.buf;
  76.     bb.cnt = BFSIZ;
  77.     bb.count = 0;
  78.     bb.f = stdout;
  79. #ifdef    PROTOTYPES
  80.     va_start(args, form);
  81. #else
  82.     va_start(args);
  83. #endif
  84.     format(_bput, (long)&bb, form, args);
  85.     va_end(args);
  86.     if (bb.cnt < BFSIZ)
  87.         _bflush (&bb);
  88.     return (bb.count);
  89. }
  90.  
  91. /* VARARGS3 */
  92. #ifdef    PROTOTYPES
  93. EXPORT int fprintf(FILE *file, const char *form, ...)
  94. #else
  95. EXPORT int fprintf(file, form, va_alist)
  96.     FILE    *file;
  97.     char    *form;
  98.     va_dcl
  99. #endif
  100. {
  101.     va_list    args;
  102.     _BUF    bb;
  103.  
  104.     bb.ptr = bb.buf;
  105.     bb.cnt = BFSIZ;
  106.     bb.count = 0;
  107.     bb.f = file;
  108. #ifdef    PROTOTYPES
  109.     va_start(args, form);
  110. #else
  111.     va_start(args);
  112. #endif
  113.     format(_bput, (long)&bb, form, args);
  114.     va_end(args);
  115.     if (bb.cnt < BFSIZ)
  116.         _bflush (&bb);
  117.     return (bb.count);
  118. }
  119.